class P488_39643 {

    public static void main(String[] args) {
    	int cases = Integer.parseInt(readLn());
    	
    	for (int k = 0; k < cases; k++ ) {
    		readLn();
    		process();
    		
    		if (k + 1 < cases) System.out.println();
    	}
    }

    private static void process() {
    	int amp = Integer.parseInt(readLn());
    	int feq = Integer.parseInt(readLn());
    	
    	StringBuffer sb = new StringBuffer();
    	
    	for (int k = 1; k < amp; k++) {
    		for (int i = 1; i <= k; i++) {
    			sb.append(k);
    		}
    		sb.append("\n");
    	}
    	
    	for (int k = amp; k >= 1; k--) {
    		for (int i = 1; i <= k; i++) {
    			sb.append(k);
    		}
    		sb.append("\n");
    	}

    	String wave = sb.toString().trim();
    	
    	for (int k = 0; k < feq; k++) {
    		
    		System.out.println(wave);
    		
    		if (k + 1 < feq) System.out.println();
    	}
		
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

}